import type { ProFormInstance } from '@ant-design/pro-components';
import { ProForm, ProFormDigit, ProFormText, ProFormTextArea } from '@ant-design/pro-components';

export interface Props {
  formRef: React.MutableRefObject<ProFormInstance<any> | undefined>;
  formData: GoodsListManagementApi.FormData;
  setFormData: React.Dispatch<React.SetStateAction<GoodsListManagementApi.FormData>>;
}

function GoodsListManagementCouponForm(props: Props) {
  const { formData, setFormData } = props;

  return (
    <ProForm.Item name="couponTemplateInputs">
      <ProFormText
        width="md"
        required
        name={['couponTemplateInputs', 'name']}
        label="优惠名称"
        placeholder="请输入优惠名称"
        rules={[{ required: true }]}
        fieldProps={{
          value: formData.couponTemplateInputs?.name,
          onChange: (e) =>
            setFormData({
              ...formData,
              couponTemplateInputs: {
                ...formData.couponTemplateInputs,
                name: e.target.value,
              },
            }),
        }}
      />
      <ProForm.Group>
        <ProFormDigit
          required
          width="md"
          name={['couponTemplateInputs', 'discountValue']}
          min={0}
          label="折扣金额"
          placeholder="请输入折扣金额"
          rules={[{ required: true }]}
          fieldProps={{
            value: formData.couponTemplateInputs?.discountValue,
            onChange: (value) =>
              setFormData({
                ...formData,
                couponTemplateInputs: {
                  ...formData.couponTemplateInputs,
                  discountValue: value || 0,
                },
              }),
          }}
        />
        <ProFormDigit
          required
          width="md"
          name={['couponTemplateInputs', 'minAmount']}
          min={0}
          label="最小金额"
          placeholder="请输入最小金额"
          rules={[{ required: true }]}
          fieldProps={{
            value: formData.couponTemplateInputs?.minAmount,
            onChange: (value) =>
              setFormData({
                ...formData,
                couponTemplateInputs: {
                  ...formData.couponTemplateInputs,
                  minAmount: value || 0,
                },
              }),
          }}
        />
      </ProForm.Group>
      <ProForm.Group>
        <ProFormDigit
          required
          width="md"
          name={['couponTemplateInputs', 'expireDays']}
          min={0}
          label="有限天数"
          placeholder="请输入有限天数"
          rules={[{ required: true }]}
          fieldProps={{
            value: formData.couponTemplateInputs?.expireDays,
            onChange: (value) =>
              setFormData({
                ...formData,
                couponTemplateInputs: {
                  ...formData.couponTemplateInputs,
                  expireDays: value || 0,
                },
              }),
          }}
        />
        <ProFormDigit
          required
          width="md"
          name={['couponTemplateInputs', 'qty']}
          min={0}
          label="券数量"
          placeholder="请输入券数量"
          rules={[{ required: true }]}
          fieldProps={{
            value: formData.couponTemplateInputs?.qty,
            onChange: (value) =>
              setFormData({
                ...formData,
                couponTemplateInputs: {
                  ...formData.couponTemplateInputs,
                  qty: value || 0,
                },
              }),
          }}
        />
      </ProForm.Group>
      <ProFormTextArea
        name={['couponTemplateInputs', 'description']}
        label="优惠描述"
        placeholder="请输入优惠描述"
        fieldProps={{
          value: formData.couponTemplateInputs?.description,
          onChange: (e) =>
            setFormData({
              ...formData,
              couponTemplateInputs: {
                ...formData.couponTemplateInputs,
                description: e.target.value,
              },
            }),
        }}
      />
    </ProForm.Item>
  );
}
export default GoodsListManagementCouponForm;
